<?php

namespace api\controller;

// +----------------------------------------------------------------------
// | 数据控制层
// +----------------------------------------------------------------------

use common\controller\VerifyController;
use common\service\DeadlineTaskService;
use think\Request;
use think\Response;

class DeadlineTaskController extends VerifyController
{

    /**
     * 获取任务消息
     * @param Request $request
     * @return Response
     */
    public function pop(Request $request)
    {
        $deadlineService = new DeadlineTaskService($request->getTenantId());
        $resData = $deadlineService->pop();

        return json(success_response('', $resData));
    }

    /**
     * 修改任务状态
     * @param Request $request
     * @return Response
     */
    public function updateDeadLine(Request $request)
    {
        $param = $request->param();
        $deadlineService = new DeadlineTaskService($request->getTenantId());

        $resData = $deadlineService->updateDeadLine($param);
        return json(success_response('', $resData));
    }

    /**
     * 创建任务消息
     * @param Request $request
     * @return Response
     */
    public function addDeadline(Request $request)
    {
        $param = $request->param();
        $data = $param['data'] ?? [];
        $jobId = $param['job_id'] ?? '';

        $deadlineService = new DeadlineTaskService($request->getTenantId());
        $resData = $deadlineService->push($data, $jobId);

        return json(success_response('', $resData));
    }

    /**
     * 查询进行中的任务
     * @param Request $request
     * @return Response
     */
    public function deadlineTaskList(Request $request)
    {
        $param = $request->param();

        $deadlineService = new DeadlineTaskService($request->getTenantId());
        $resData = $deadlineService->deadlineTaskList();

        return json(success_response('', $resData));
    }

}
